<?php
class User_model extends CI_Model{
	var $_tableName = 'users';
    function __construct(){
        // Call the Model constructor
        parent::__construct();
    }
	public function saveSocialData($params){
		/*$sql = "INSERT INTO " . $this->_tableName . "
		(user_social_id, user_email, user_fullname, user_role, user_sso, user_gender, user_sso_rawdata)
		VALUES
		()";*/
		$sqlInsert = $this->db->insert_string($this->_tableName, $params);
		$i = 1;
		$sep = "";
		$count = count($params);
		foreach($params as $field => $value){
			if($i < $count){
				$sep = ', ';
			}
			else{
				$sep = '';
			}
			$sqlUpdate .= "`$field` = '$value'".$sep;
			
			$i++;
		}
		$socialQuery = $sqlInsert . " ON DUPLICATE KEY UPDATE " . $sqlUpdate;
		if($this->db->query($socialQuery)){
			$sqlInfo = "SELECT user_id, user_fullname FROM " . $this->_tableName . " WHERE user_social_id='".$params['user_social_id']."'";
			$query = $this->db->query($sqlInfo);
			return $query->result_array();
		}
		return false;
	}
}